package com.bw.paper.mvp.view.Fragment.Live.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;

public class LiveVpAdapter extends PagerAdapter {

    private String[]titles = {"直播间","评论"};
    private RecyclerView rootRv;
//    private List<View>list = new ArrayList<>();
//    public LiveVpAdapter(){
//        TextView tv = new TextView()
//    }


    public RecyclerView getRootRv() {
        return rootRv;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull @NotNull View view, @NonNull @NotNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
        View view = (View) object;
        container.removeView(view);
    }

    @NotNull
    @Override
    public Object instantiateItem(@NonNull @NotNull ViewGroup container, int position) {
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        if (position==0){
            //创建直播间View
            TextView tv = new TextView(container.getContext());
            tv.setText("当前为直播间");
            tv.setLayoutParams(lp);
            container.addView(tv);
            return tv;
        }else {
            //创建评论列表
            RecyclerView rv = new RecyclerView(container.getContext());
            rv.setLayoutParams(lp);
            LinearLayoutManager manager = new LinearLayoutManager(container.getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            rv.setLayoutManager(manager);
            rootRv = rv;
            container.addView(rv);
            return rv;
        }
    }

    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}